package com.example.HelloSpace;

import android.app.AlertDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;

import androidx.appcompat.app.AppCompatActivity;

import com.example.HelloSpace.network.RetrofitClient;
import com.example.HelloSpace.network.WebApiService;
import com.example.HelloSpace.repository.MissionRepository;
import com.example.HelloSpace.utils.NotificationHelper;

public class MainActivity extends AppCompatActivity {
    //private MissionDetailsViewModel model;
    private WebApiService webApiService;
    private MissionRepository missionRepository;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if (savedInstanceState == null) {
            getSupportFragmentManager()
                    .beginTransaction()
                    .replace(R.id.fragment_container, new MainFragment())
                    .commit();
        }

        webApiService = RetrofitClient.getClient().create(WebApiService.class);

        // 初始化Repository并传入webApiService
        missionRepository = new MissionRepository(webApiService,this);

        NotificationHelper.createNotificationChannel(this);
//        new AlertDialog.Builder(this)
//                .setTitle("通知未启用")
//                .setMessage("为了确保您能及时收到提醒，请允许我们的应用发送通知。")
//                .setPositiveButton("去设置", (dialog, which) -> {
//                    Intent intent;
//                    intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
//                            .putExtra(Settings.EXTRA_APP_PACKAGE, getPackageName());
//                    startActivity(intent);
//                })
//                .setNegativeButton("取消", null)
//                .show();
    }

    public MissionRepository getMissionRepository() {
        return missionRepository;
    }
}